<!-- 在线统计下的在线明细 -->
<template>
  <div>
    <Table border :columns="columns" :data="tableData" :loading="tableLoading">
      <template slot-scope="{ row, index }" slot="mapBtton">
        <Button disabled type="default" :Title="$t('map')" icon="md-globe" style="margin-right: 3px" @click=""></Button>
      </template>
    </Table>
    <TopnavPage v-model="queryParam.page" @changePage="changePage">
    </TopnavPage>
  </div>
</template>
<script>
import TopnavPage from "_c/topnav/TopnavPage";
import DeviceOnline from "@/api/DeviceOnline"
import {apiResult} from "@/libs/util";
export default {
  name: "StatisticsOnlineDetail",
  components:{TopnavPage},
  props:{
    deviceId:{
      type:Number,
      default: () => { return 0;} //对象参数必须这样写
    },
    dateRange:{
      type: Array,
      default:() => []
    }
  },
  computed:{
    columns(){
      return [
        {title: this.$t('start_time'), key: 'startTime', sortable: true,width: 200,align: 'left'},
        {title: this.$t('end_time'), key: 'endTime', sortable: true, width: 200,align: 'left'},
        {title: this.$t('online_time'), key: 'onlineMin', sortable: true, ellipsis:true,width: 180}]
    }
  },
  data(){
    return{
      api: new DeviceOnline(),

      queryParam:{
        page: {
          desc: [],
          pages: 1,
          size: 15,
          total: 0,
          current: 1,
        },
        where: {
          keyword:null,
          deviceId: null,
          fromTime: null,
          toTime: null,
        },
      },
      tableData: [],
      tableLoading:false,
    }

  },
  methods:{
    changePage(){
      this.getData()
    },
    getData(){
      this.tableLoading = true;
      /** 生成查询条件 */
      if (!(this.dateRange == null || this.dateRange.length < 2 || this.dateRange[0]=="")){
        this.queryParam.where.fromTime = this.dateRange[0];
        this.queryParam.where.toTime = this.dateRange[1];
      }
      this.queryParam.where.deviceId = this.deviceId;
      this.api.queryPage(JSON.stringify(this.queryParam)).then(res => {
        this.tableData = [];
        apiResult(res.data,false,result=>{
          this.queryParam.page.total = result.data.total;
          this.tableData = result.data.records;
        })
        this.tableLoading = false;
      })
    }
  },
  mounted() {
    console.log(">>>>>>> StatisticsOnline.getData: dateRange=%o,deviceId=%o",this.dateRange,this.deviceId);
    this.getData();
  }

}

</script>
<style>

</style>
